﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace MyWeb.Data
{
    public class ShopController : SqlDataProvider
    {
        #region[Shop_Insert]
        public void Shop_Insert(ShopInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Shop_Insert", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                cmd.Parameters.Add(new SqlParameter("@Address", data.Address));
                cmd.Parameters.Add(new SqlParameter("@Tel", data.Tel));
                cmd.Parameters.Add(new SqlParameter("@Province_Id", data.Province_Id));
                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region[Shop_Update]
        public void Shop_Update(ShopInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Shop_Update", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                cmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                cmd.Parameters.Add(new SqlParameter("@Address", data.Address));
                cmd.Parameters.Add(new SqlParameter("@Tel", data.Tel));
                cmd.Parameters.Add(new SqlParameter("@Province_Id", data.Province_Id));
                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region[Shop_Delete]
        public void Shop_Delete(string Id)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Shop_Delete", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Id", Id));
                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region[Shop_GetByAll]
        public DataTable Shop_GetByAll()
        {
            using (SqlCommand cmd = new SqlCommand("sp_Shop_GetByAll", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable ds = new DataTable();
                da.Fill(ds);
                return ds;
            }
        }
        #endregion

        #region[Shop_GetById]
        public DataTable Shop_GetById(string Id)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Shop_GetById", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable ds = new DataTable();
                da.Fill(ds);
                return ds;
            }
        }
        #endregion

        #region[Shop_GetByTop]
        public DataTable Shop_GetByTop(string Top, string Where, string Order)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Shop_GetByTop", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Top", Top));
                cmd.Parameters.Add(new SqlParameter("@Where", Where));
                cmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable ds = new DataTable();
                da.Fill(ds);
                return ds;
            }
        }
        #endregion
    }
}
